package com.fancy.common.utils;

import java.util.Locale;

import org.springframework.util.Assert;

public class LocaleUtil {

	/**
	 * 获取语言
	 * 
	 * @param language
	 * @return
	 */
	public static Locale getLocale(final String language) {
		Assert.notNull(language, "language can not be null");
		return Locale.forLanguageTag(language.replace("_", "-"));
	}

	/**
	 * 获取语言
	 * 
	 * @param language
	 * @return
	 */
	public static String getLang(final Locale locale) {
		Assert.notNull(locale, "locale can not be null");
		String lang = locale.toLanguageTag().replace("-", "_");
		if("he".equalsIgnoreCase(lang)){
			lang = "iw";
		}
		return lang;
	}

	public static void main(String[] args) {
		System.out.println(LocaleUtil.getLang(Locale.TAIWAN));
	}
}